Add a testcase for counting selection in treeviews
authorMatthias Clasen <mclasen@redhat.com>
Sat, 30 Aug 2014 05:44:20 +0000 (01:44 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 Aug 2014 05:46:58 +0000 (01:46 -0400)
https://bugzilla.gnome.org/show_bug.cgi?id=702957

testsuite/gtk/treeview.c

index 5f804ab8c56a2c62a287cac30310c1b187875203..499376eb1af5a3fbe3d689d7c4ef8ae417771317 100644 (file)
@@ -236,6 +236,59 @@ test_row_separator_height (void)
   gtk_widget_destroy (tree_view);
 }
 
+static void
+test_selection_count (void)
+{
+  GtkTreePath *path;
+  GtkListStore *list_store;
+  GtkTreeSelection *selection;
+  GtkWidget *view;
+
+  g_test_bug ("702957");
+
+  list_store = gtk_list_store_new (1, G_TYPE_STRING);
+  view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
+
+  gtk_list_store_insert_with_values (list_store, NULL, 0, 0, "One", -1);
+  gtk_list_store_insert_with_values (list_store, NULL, 1, 0, "Two", -1);
+  gtk_list_store_insert_with_values (list_store, NULL, 2, 0, "Tree", -1);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+  gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 0);
+
+  path = gtk_tree_path_new_from_indices (0, -1);
+  gtk_tree_selection_select_path (selection, path);
+  gtk_tree_path_free (path);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 1);
+
+  path = gtk_tree_path_new_from_indices (2, -1);
+  gtk_tree_selection_select_path (selection, path);
+  gtk_tree_path_free (path);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 2);
+
+  path = gtk_tree_path_new_from_indices (2, -1);
+  gtk_tree_selection_select_path (selection, path);
+  gtk_tree_path_free (path);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 2);
+
+  path = gtk_tree_path_new_from_indices (1, -1);
+  gtk_tree_selection_select_path (selection, path);
+  gtk_tree_path_free (path);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 3);
+
+  gtk_tree_selection_unselect_all (selection);
+
+  g_assert_cmpint (gtk_tree_selection_count_selected_rows (selection), ==, 0);
+
+  gtk_widget_destroy (view);
+}
+
 int
 main (int    argc,
       char **argv)
@@ -249,6 +302,7 @@ main (int    argc,
                    test_select_collapsed_row);
   g_test_add_func ("/TreeView/sizing/row-separator-height",
                    test_row_separator_height);
+  g_test_add_func ("/TreeView/selection/count", test_selection_count);
 
   return g_test_run ();
 }